package kim.artemis.rpc.core.common.enums;

import cn.hutool.core.util.StrUtil;
import kim.artemis.rpc.core.protocol.serializer.ArtemisSerializer;
import kim.artemis.rpc.core.protocol.serializer.KryoSerializer;
import kim.artemis.rpc.core.protocol.serializer.ProtostuffSerializer;
import lombok.Getter;

/**
 * 序列化枚举
 * @author Wq.
 */
public enum SerializerEnum {

    Kryo (new KryoSerializer()),
    Protostuff (new ProtostuffSerializer());

    @Getter
    private ArtemisSerializer serializer;

    SerializerEnum(ArtemisSerializer serializer) {
        this.serializer = serializer;
    }

    public static SerializerEnum match(String name, SerializerEnum defaultSerializer){
        if (StrUtil.isNotBlank(name)) {
            for (SerializerEnum item: SerializerEnum.values()) {
                if (item.name().equals(name)) {
                    return item;
                }
            }
        }
        return defaultSerializer;
    }

}
